# 定义登录页面元素
# 定义对象库层
import allure
from selenium.webdriver.common.by import By

from base.tmp.base import base_tmp, bases_tmp


class login(base_tmp):
    def __init__(self):
        super().__init__()
        # 定位登录按钮
        self.star = By.XPATH, '/html/body/div[1]/div[1]/div/div/div[2]/a[1]'
        # 定位用户输入框
        self.username = By.XPATH, '//*[@id="username"]'
        # 定位密码输入框
        self.password = By.XPATH, '//*[@id="password"]'
        # 定位验证码输入框
        self.code = By.XPATH, '//*[@id="verify_code"]'
        # 定位登录按钮
        self.stars = By.XPATH, '//*[@id="loginform"]/div/div[6]/a'

    def st(self):
        return self.get_element(self.star)
    def user(self):
        return self.get_element(self.username)
    def pas(self):
        return self.get_element(self.password)
    def cod(self):
        return self.get_element(self.code)
    def sts(self):
        return self.get_element(self.stars)

# 定义操作层
class login_imp(bases_tmp):
    def __init__(self):
        super().__init__()
        self.login = login()

    @allure.step(title="跳转登录页面")
    def star(self):
        return self.login.st().click()

    @allure.step(title="输入账户")
    def get_name(self, user):
        return self.imp_sta(self.login.user(), user)

    @allure.step(title="输入密码")
    def get_password(self, password):
        return self.imp_sta(self.login.pas(), password)

    @allure.step(title="输入验证码")
    def get_code(self, code):
        return self.imp_sta(self.login.cod(), code)

    @allure.step(title="点击登录")
    def get_start(self):
        return self.login.sts().click()

# 定义业务层
class login_sta:
    def __init__(self):
        self.login = login_imp()

    def start(self, user, password, code):
        self.login.star()
        self.login.get_name(user)
        self.login.get_password(password)
        self.login.get_code(code)
        self.login.get_start()